package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ExchangeVarietyRate;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Financialsecurities;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Stocksector;

import java.util.List;
import java.util.Map;

/**
 * 功能：证券信息数据层接口类
 * 编写者：蒋玲苹
 * 日期：21-02-18
 * 版本：1.0
 */
@Repository
public interface FinancialsecuritiesDao {
    /**
     * 添加数据
     * @param financialsecurities
     * @return 0:添加失败,1:添加成功
     */
    @Insert("insert into financialsecurities values(#{seId},#{seName},#{seType},#{breedRateId},to_date('${issueDate}','yyyy-MM-dd'),to_date('${delayDate}','yyyy-MM-dd'),#{stockId})")
    public int add(Financialsecurities financialsecurities);

    /**
     * 删除数据
     * @param seId
     * @return 删除影响的行数(0:删除失败,1:删除成功)
     */
    @Delete("delete from financialsecurities where seId='${seId}'")
    public int delete(@PathVariable("seId") String seId);

    /**
     * 修改数据
     * @param financialsecurities
     * @return
     */
    @Update("update financialsecurities set seName=#{seName},seType=#{seType},breedRateId=#{breedRateId},issueDate=to_date('${issueDate}','yyyy-MM-dd'),delayDate=to_date('${delayDate}','yyyy-MM-dd'),stockId=#{stockId} where seId=#{seId}")
    public int update(Financialsecurities financialsecurities);

    /**
     * 分页查询所有数据
     * @param map
     * @return
     */
    /**
     * 查询数据
     * @param map 集合
     * @return
     */
    @Select("<script>" +
            "select seId,seName,seType,BreedRateId as breedRateId,to_char(issueDate,'yyyy-MM-dd') as issueDate,to_char(delayDate,'yyyy-MM-dd') as delayDate,stockId from " +
            " (select rownum rn,financialsecurities.* from financialsecurities " +
            " <where>#{end}>=rownum</where>)  " +
            "<where>" +
            "<if test='financialsecurities.seName!=null'>" +
            " and seName like '%${financialsecurities.seName}%'" +
            "</if>" +
            "<if test='financialsecurities.seType!=0'>" +
            " and seType=#{financialsecurities.seType}" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
    public List<Financialsecurities> queryAll(Map<String, Object> map);

    /**
     * 统计记录数
     * @return
     */
    @Select("select count(*) from financialsecurities")
    public int count();
    @Select("select * from exchangeVarietyRate")
    public List<ExchangeVarietyRate> ex();
    @Select("select * from stocksector")
    public List<Stocksector> sr();

    /**
     * 删除债券数据
     * @param bondId
     * @return 删除影响的行数(0:删除失败,1:删除成功)
     */
    @Delete("delete from securitiesInformation where bondId=#{bondId}")
    public int deletes(@Param("bondId") String bondId);
}
